package com.eshop.we.controller;

 import com.baomidou.mybatisplus.plugins.Page;
import com.eshop.we.business.LeaseBusiness;
import com.eshop.we.lease.dto.LeaseDto;
import com.eshop.we.lease.entity.Lease;
import com.eshop.we.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

 /**
 * @author wangzhanguo
 * @create 2018-06-05 10:54
 **/
@RestController
@RequestMapping("/lease")
public class LeaseController extends BaseController {

    @Autowired
    private LeaseBusiness leaseBusiness;

    /**
     * 本校租书信息
     * @return
     */
    @RequestMapping("/self")
    public Result self(Page<LeaseDto> page, Integer schoolId){
       return Result.success(leaseBusiness.selectSelfPage(page,schoolId));
    }

    /**
     * 附近学校租书信息
     * @return
     */
    @RequestMapping("/near")
    public Result near(Page<LeaseDto> page, String lng, String lat, Integer distance){
        return Result.success(leaseBusiness.selectNearPage(page,lng,lat,distance));
    }

    /**
     * 添加租书信息
     * @return
     */
    @RequestMapping("/add")
    public Result add(Lease lease){
        lease.setCtime(new Long(System.currentTimeMillis()/1000).intValue());
        return Result.success(leaseBusiness.insert(lease));
    }
}
